package com.ms.pda.extensions


import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.BindingAdapter
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.ms.pda.R
import com.ms.pda.adapter.*
import com.ms.pda.model.vo.*

object SubmitDataBindingAdapter {

    /**
     * 提交错误失败
     */
    @JvmStatic
    @BindingAdapter(value = ["submitFailedAdapter", "submitFailedData"])
    fun RecyclerView.submitFailedAdapter(activity: AppCompatActivity, data: List<SubmitFailedVO>) {
        if (this.adapter == null) {
            this.layoutManager = LinearLayoutManager(activity)
            val adapter = SubmitFailedRVAdapter()
            this.adapter = adapter
        }
        ((this.adapter) as SubmitFailedRVAdapter).setList(data)
        if (((this.adapter) as SubmitFailedRVAdapter).data.isEmpty()) ((this.adapter) as SubmitFailedRVAdapter).setEmptyView(
            R.layout.item_empty
        )
    }
}